package com.myblog.Utils;

import com.myblog.domain.entity.LoginUser;
import com.myblog.domain.entity.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.List;

public class SecurityUtils {


    public static LoginUser getLoginUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return (LoginUser) authentication.getPrincipal();
    }
    public static Long getUserId(){
        LoginUser loginUser=getLoginUser();
        User user=loginUser.getUser();
        return user.getId();
    }

    public static boolean isAdmin(){
        return getUserId()==1L;
    }
    public static List<String> getPermission(){
        LoginUser loginUser = getLoginUser();
        return loginUser.getPerms();
    }


}
